﻿Imports System.Runtime.CompilerServices
Imports Mystery

Public Interface IContentActionButton

    ReadOnly Property name As String
    ReadOnly Property image As Image
    ReadOnly Property text As String
    Function canExecute() As Boolean
    Function execute() As Boolean

End Interface

Public Class ContentDeleteAction
    Implements IContentActionButton

    Private _content As Icontent

    Public Sub New(content As IContent)
        _content = content
    End Sub


    Public Function canExecute() As Boolean Implements MysteryControls.IContentActionButton.canExecute
        Return True
    End Function

    Public Function execute() As Boolean Implements MysteryControls.IContentActionButton.execute
        Dim cd As IContentDispatcher = getGlobalObject(Of IContentDispatcher)()
        Dim result As Boolean = cd.Remove(_content)
        'Dim ir As InterfaceStatus = getGlobalObject(Of InterfaceStatus)()
        'ir.showType(Nothing, force_reload:=True)
        Return result
    End Function

    Public ReadOnly Property image As System.Windows.Controls.Image Implements MysteryControls.IContentActionButton.image
        Get
            Dim result As New Image()
            Dim bit As BitmapImage = New BitmapImage(New Uri("/MysteryControls;component/Images/DeleteRed.png", UriKind.RelativeOrAbsolute))
            result.Source = bit
            Return result
        End Get
    End Property

    Public ReadOnly Property name As String Implements MysteryControls.IContentActionButton.name
        Get
            Return "delete"
        End Get
    End Property

    Public ReadOnly Property text As String Implements MysteryControls.IContentActionButton.text
        Get
            Return "Delete"
        End Get
    End Property
End Class


Public Class ContentActionWithDelete
    Implements IContentActionButtonProvider

    Public Function getAll(content As Mystery.IContent) As System.Collections.Generic.IEnumerable(Of MysteryControls.IContentActionButton) Implements MysteryControls.IContentActionButtonProvider.getAll
        If content Is Nothing Then Return New List(Of IContentActionButton)
        Return New List(Of IContentActionButton) From {New ContentDeleteAction(content)}
    End Function
End Class

Public Module ContentActionButtonExt
    <Extension()>
    Public Function createSmallButton(action As IContentActionButton) As Button
        Dim result As New Button
        Dim img As Image = action.image
        result.Content = img
        result.Width = 60
        result.Height = 60
        result.IsEnabled = action.canExecute
        result.ToolTip = action.text
        AddHandler result.Click, AddressOf action.execute
        Return result
    End Function
End Module



